{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "在调用或流式传输graph时，可以设置graph递归限制。递归限制设置了在引发错误之前，graph允许执行的超级步数。有关递归限制的概念，请在此处阅读更多信息。让我们通过一个具有并行分支的简单graph的示例来看看递归限制是如何工作的，以便更好地理解。\n",
    "\n",
    "如果你想了解一个示例，该示例说明了如何在graph中返回状态的最后一个值，而不是收到递归限制错误，请阅读这篇操作指南。https://langchain-ai.github.io/langgraph/how-tos/recursion-limit/"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "cb891874e518285b"
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "\n",
    "from langgraph.constants import START, END\n",
    "from langgraph.graph import StateGraph\n",
    "import operator\n",
    "from typing import TypedDict, Annotated\n",
    "\n",
    "\n",
    "class State(TypedDict):\n",
    "    # The operator.add reducer fn makes this append-only\n",
    "    aggregate:Annotated[list,operator.add]\n",
    "    \n",
    "def node_a(state:State):\n",
    "    return {\"aggregate\":[\"A\"]}\n",
    "\n",
    "def node_b(state:State):\n",
    "    return {\"aggregate\":[\"B\"]}\n",
    "\n",
    "def node_c(state:State):\n",
    "    return {\"aggregate\":[\"C\"]}\n",
    "\n",
    "def node_d(state:State):\n",
    "    return {\"aggregate\":[\"D\"]}\n",
    "\n",
    "workflow = StateGraph(State)\n",
    "# 构建节点\n",
    "workflow.add_node(\"a\", node_a)\n",
    "workflow.add_node(\"b\", node_b)\n",
    "workflow.add_node(\"c\", node_c)\n",
    "workflow.add_node(\"d\", node_d)\n",
    "\n",
    "# 添加开始边\n",
    "workflow.add_edge(START, \"a\")\n",
    "# 添加结束边\n",
    "workflow.add_edge(\"d\", END)\n",
    "\n",
    "# 添加边\n",
    "workflow.add_edge(\"a\", \"b\")\n",
    "workflow.add_edge(\"a\", \"c\")\n",
    "workflow.add_edge(\"b\", \"d\")\n",
    "workflow.add_edge(\"c\", \"d\")\n",
    "\n",
    "# 调用graph\n",
    "graph = workflow.compile()\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-11-04T06:03:08.984119Z",
     "start_time": "2024-11-04T06:03:08.973165Z"
    }
   },
   "id": "f4989f074af35cce",
   "execution_count": 12
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "image/jpeg": "/9j/4AAQSkZJRgABAQAAAQABAAD/4gHYSUNDX1BST0ZJTEUAAQEAAAHIAAAAAAQwAABtbnRyUkdCIFhZWiAH4AABAAEAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAACRyWFlaAAABFAAAABRnWFlaAAABKAAAABRiWFlaAAABPAAAABR3dHB0AAABUAAAABRyVFJDAAABZAAAAChnVFJDAAABZAAAAChiVFJDAAABZAAAAChjcHJ0AAABjAAAADxtbHVjAAAAAAAAAAEAAAAMZW5VUwAAAAgAAAAcAHMAUgBHAEJYWVogAAAAAAAAb6IAADj1AAADkFhZWiAAAAAAAABimQAAt4UAABjaWFlaIAAAAAAAACSgAAAPhAAAts9YWVogAAAAAAAA9tYAAQAAAADTLXBhcmEAAAAAAAQAAAACZmYAAPKnAAANWQAAE9AAAApbAAAAAAAAAABtbHVjAAAAAAAAAAEAAAAMZW5VUwAAACAAAAAcAEcAbwBvAGcAbABlACAASQBuAGMALgAgADIAMAAxADb/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCAGwAI8DASIAAhEBAxEB/8QAHQABAAMAAwEBAQAAAAAAAAAAAAUGBwMECAIBCf/EAFYQAAEDAwED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Ms5mkBgb0DBzj51CXDYqamK5TUt9kobtJqB2oaGujpg7rSR0TIjG5hdiRpa1wPFud7oxxwcNoSum/DKy8b3/8B09lDby3aptHbfn0MlxEdsDpLcx7IXDkpcENeSQcc4yf1rWVm1m07etnt4vl/rX1utrhezTRyx2ujgpeQELHgHEk4Bad7wkg+Holxr+6EH+gGphgdLqDj/8AaW9F+rhuyTvd8823pcFyRzQ5paQCCMEHpVcsWrK68V4p6jSd6s8ZaXdc1xpTGCOj3ud7sn9SnqqobSU8kzgXBgzutGS49AA6SeYDpXqjJSxQN62QV8lw2b2R8pLnwxOpd4nJIie6IEnpOGDiriq9s+sEml9F2i2zgNqYYA6cNOQJXEvkAPSN5zlYV+ZbTKMq85Qybduly7zCIi8xAREQBERAYxr7ZXV2yrnuen6Z1ZQykyTW2LHKQuPFzoskBzDz7nODndyCGtzWS7UcEzoZ6hlNOw4dDUHkpGnytdgj6F6xXBVUNNXN3amniqG+CVgcPtX0ezemp0oKFWO9bW9n53JweZ5V7L0P6bT/AFrfanZeh/Taf61vtXp/tatHiqi9HZ7E7WrR4qovR2exe737T/bff9iLI8wdl6H9Np/rW+1Oy9D+m0/1rfavT/a1aPFVF6Oz2J2tWjxVRejs9ie/af7b7/sLI8wdl6H9Np/rW+1Oy9D+m0/1rfavT/a1aPFVF6Oz2J2tWjxVRejs9ie/af7b7/sLI8xQ3Knq52wUjzXVLshtPRtM0jv1NZkrV9nOy6pjrILzqCEQPhcJKS3bwcWO6JJccN4c7WgkDg4kuwGalT0kFGzcghjgb+bGwNH2LmXP2v0xUrwdOnHdTzxu/InBZBERfPEBERAf/9k=",
      "text/plain": "<IPython.core.display.Image object>"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from IPython.core.display import Image\n",
    "\n",
    "display(Image(graph.get_graph().draw_mermaid_png()))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-11-04T06:03:09.793808Z",
     "start_time": "2024-11-04T06:03:08.987857Z"
    }
   },
   "id": "d1c205546f3eb3e",
   "execution_count": 13
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 使用graph"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "36a1138834c2c3a6"
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Recursion Error\n"
     ]
    }
   ],
   "source": [
    "from langgraph.errors import GraphRecursionError\n",
    "\n",
    "try:\n",
    "    graph.invoke({\"aggregate\": []}, {\"recursion_limit\": 3})\n",
    "except GraphRecursionError:\n",
    "    print(\"Recursion Error\")\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-11-04T06:03:09.807886Z",
     "start_time": "2024-11-04T06:03:09.797716Z"
    }
   },
   "id": "b12af7d8967a49e5",
   "execution_count": 14
  },
  {
   "cell_type": "code",
   "outputs": [],
   "source": [
    "try:\n",
    "    graph.invoke({\"aggregate\": []}, {\"recursion_limit\": 4})\n",
    "except GraphRecursionError:\n",
    "    print(\"Recursion Error\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-11-04T06:03:32.990262Z",
     "start_time": "2024-11-04T06:03:32.981671Z"
    }
   },
   "id": "6f585e643587161d",
   "execution_count": 16
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
